class SensorManager {
    constructor() {
        this.sensorData = {
            soilMoisture: 0,
            airTemperature: 0,
            airHumidity: 0
        };
    }

    // 模拟获取传感器数据
    async fetchSensorData() {
        // 这里应该替换为实际的API调用
        this.sensorData = {
            soilMoisture: Math.random() * 100,
            airTemperature: 20 + Math.random() * 10,
            airHumidity: Math.random() * 100
        };
        this.updateUI();
    }

    updateUI() {
        document.getElementById('soil-moisture').textContent = 
            this.sensorData.soilMoisture.toFixed(1);
        document.getElementById('air-temperature').textContent = 
            this.sensorData.airTemperature.toFixed(1);
        document.getElementById('air-humidity').textContent = 
            this.sensorData.airHumidity.toFixed(1);
    }

    async fetchWeatherData() {
        // 这里应该替换为实际的天气API调用
        const weatherData = {
            condition: ['晴朗', '多云', '小雨'][Math.floor(Math.random() * 3)],
            temperature: (20 + Math.random() * 15).toFixed(1),
            humidity: Math.floor(40 + Math.random() * 40)
        };

        document.getElementById('weather-condition').textContent = weatherData.condition;
        document.getElementById('current-temperature').textContent = `${weatherData.temperature}°C`;
        document.getElementById('current-humidity').textContent = `${weatherData.humidity}%`;
    }

    // 判断是否需要灌溉
    needsIrrigation() {
        const threshold = parseFloat(document.getElementById('moisture-threshold').value);
        return this.sensorData.soilMoisture < threshold;
    }
} 